//
//  ViewController.m
//  UI03_UIViewController_CustomView
//
//  Created by wyx on 16/3/11.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "ViewController.h"
#import "LTView.h"
#import "MyButton.h"
#import "VCOfSecond.h"

//延展
@interface ViewController() <UITextFieldDelegate>
@end

@implementation ViewController
/** 初始化 */
- (instancetype)init {
    self = [super init];
//    if (self) {
//        NSLog(@"%s, %d",__FUNCTION__,__LINE__);
//    }
    return self;
}
/** 首先从图形化(nib)进行初始化,如果没有 nib文件,尝试从代码初始化,所以无论是图形化还是代码,都调用这个初始化方法,所以通常重写 Controller 的初始化都是重写这个方法. */
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    //if (self) {
         //NSLog(@"%s, %d", __FUNCTION__,__LINE__);
    //}
    return self;
}
/** 加载视图 */
- (void)loadView{
    [super loadView];
    //NSLog(@"%s, %d",__FUNCTION__,__LINE__);
}
/** 加载视图完毕
 *  通常,代码在此方法编写
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createSubView];
    
    //NSLog(@"%s, %d",__FUNCTION__,__LINE__);
}
- (void)createSubView {
    //用户名
    LTView *viewOfUser = [[LTView alloc] initWithFrame:CGRectMake(40, 50, self.view.frame.size.width - 80, 40) withText:@"用户名: " placeHolder:@"请输入用户名"];
    [self.view addSubview:viewOfUser];
    [viewOfUser release];
    viewOfUser.textFieldOfRight.delegate = self;
    //密码
    LTView *viewOfKey = [[LTView alloc] initWithFrame:CGRectMake(40, 110, self.view.frame.size.width  - 80, 40) withText:@"密码: " placeHolder:@"请输入密码"];
    [self.view addSubview:viewOfKey];
    [viewOfKey release];
    viewOfKey.textFieldOfRight.delegate = self;
    //确定键
    MyButton *buttonOfEnter = [MyButton buttonWithType:UIButtonTypeSystem];
    buttonOfEnter.frame = CGRectMake(100, 180, 100, 40);
    [buttonOfEnter setTitle:@"确定" forState: UIControlStateNormal];
    buttonOfEnter.titleLabel.font = [UIFont systemFontOfSize:23];
    [buttonOfEnter setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    [self.view addSubview:buttonOfEnter];
    [buttonOfEnter release];
    //取消
    MyButton *buttonOfCancle = [MyButton buttonWithType:UIButtonTypeSystem];
    buttonOfCancle.frame = CGRectMake(220, 180, 100, 40);
    [buttonOfCancle setTitle:@"取消" forState: UIControlStateNormal];
    buttonOfCancle.titleLabel.font = [UIFont systemFontOfSize:23];
    [buttonOfCancle setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    [self.view addSubview:buttonOfCancle];
    [buttonOfCancle release];
    [buttonOfCancle addTarget:self action:@selector(handleReg:) forControlEvents:UIControlEventTouchUpInside];
    
}
#pragma mark - TextField 协议
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
#pragma mark - 跳转下一界面
- (void)handleReg:(UIButton *)button {
    //创建第二界面对象
    VCOfSecond *second = [[VCOfSecond alloc] init];
    //推出第二界面(controller的方法)模态
    [self presentViewController:second animated:YES completion:^{
        
    }];
    [second release];
    
}
#pragma mark - other
/** 视图将要显示 */
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //NSLog(@"%s, %d",__FUNCTION__,__LINE__);
    
}
/** 视图已经显示 */
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    //NSLog(@"%s, %d",__FUNCTION__,__LINE__);
}
/** 内存不足时,调用此方法 */
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
